//使用mongooe来连接mongodb数据库

const mongoose = require("mongoose");

//mongodb的连接地址

let api = "mongodb://127.0.0.1:27017/H52201";

//开始连接数据库
mongoose.connect(api, { useNewUrlParser: true, useUnifiedTopology: true });

//获取连接对象,得到返回数据库
let db = mongoose.connection;

//使用事件来监听连接的状态

db.on("open", () => {
  console.log("数据库连接成功");
});

db.on("error", () => {
  console.log("连接数据库出错");
});

module.exports = mongoose;

